﻿using System.Runtime.InteropServices;
using System.Text;

namespace Com.Lancetinc.Evs.Cameras
{
    static class HCameraLib
    {
        public enum PropertyCameraControl
        {
            Pan = 0,
            Tilt = (Pan + 1),
            Roll = (Tilt + 1),
            Zoom = (Roll + 1),
            Exposure = (Zoom + 1),
            Iris = (Exposure + 1),
            Focus = (Iris + 1),
            LowlightCompensation = 19
        };

        // 获取/设置视频属性

        [DllImport("HCamera.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int hGetVideoProcAmpInfo(int devIndex, int propId, ref int min, ref int max, ref int step, ref int deft, ref int enable);

        [DllImport("HCamera.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int hGetVideoProcAmpValue(int devIndex, int propId, ref int value, ref int flag);

        [DllImport("HCamera.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int hSetVideoProcAmpValue(int devIndex, int propId, int value, int flag);

        [DllImport("HCamera.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int hRclReadMem(int devIndex, ushort regAddr, ref byte regVal);

        [DllImport("HCamera.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int hRclWriteMem(int devIndex, ushort regAddr, byte regVal);


        [DllImport("HCamera.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int hGetVideoCameraControlInfo(int devIndex, int prop, ref int min, ref int max, ref int step, ref int deft, ref int enable);

        [DllImport("HCamera.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int hGetVideoCameraControlValue(int devIndex, int prop, ref int value, ref int flag);

        [DllImport("HCamera.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int hSetVideoCameraControlValue(int devIndex, int prop, int value, int flag);

        ///
        /// 枚举/释放视频设备(枚举时返回已连接的视频设备数量，-1表示错误，两个函数必须成对使用)
        ///
        [DllImport("HCamera.dll")]
        public static extern int hEnumVideoDevice();
        
        [DllImport("HCamera.dll")]
        public static extern void hFreeVideoDevice();

        ///
        /// 获取视频设备信息
        ///
        [DllImport("HCamera.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int hGetVideoDeviceFriendlyName(int devIndex, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder szFriendlyName, int Length);
        
        [DllImport("HCamera.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int hGetVideoDeviceVIDPID(int devIndex, ref int vid, ref int pid);

    }
}
